package com.example.mapper;


import com.example.pojo.Brand;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BrandMapper {

    /**
     * 查询所有品牌
     */
    @Select("select * from brand")
    public List<Brand> findAll();

    /**
     * 根据id删除品牌
     */
    @Delete("delete from brand where brandID = #{brandID}")
    void deleteById(Integer brandID);

    /**
     * 重置自增主键
     */
    @Update("alter table brand auto_increment = 1")
    void resetAutoIncrement();

    /**
     * 更新brandID大于指定值的记录的brandID
     */
    @Update("update brand set brandID = brandID - 1 where brandID > #{brandID}")
    void decrementBrandIDAfter(Integer brandID);

    /**
     * 添加品牌
     */
    @Insert("insert into brand (brandID,brandName, create_time, update_time) values (#{brandID},#{brandName},#{createTime},#{updateTime})")
    void insert(Brand brand);

    /**
     * 根据id查询品牌
     */
    @Select("select brandID,brandName, create_time, update_time from brand where brandID = #{brandID}")
    Brand getById(Integer brandID);

    /**
     * 修改品牌
     */
    @Update("update brand set brandName = #{brandName},update_time = #{updateTime} where brandID = #{brandID}")
    void update(Brand brand);

    //获取所有品牌名称
    @Select("select brandName from brand")
    List<String> getBrandNames();

    //根据id获取名称
    @Select("select brandName from brand where brandID = #{brandID}")
    String getBrandNameById(Integer brandID);

}
